package com.haoxin.ai_course.modules.course.controller;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.haoxin.ai_course.common.annotation.SysLog;
import com.haoxin.ai_course.common.base.AbstractController;
import com.haoxin.ai_course.common.utils.HttpJsonResult;
import com.haoxin.ai_course.modules.course.biz.AcTopicAnswerResultBusiness;
import com.haoxin.ai_course.modules.course.entity.AcTopicAnswerResult;
import com.haoxin.ai_course.modules.course.entity.PO.AcTopicAnswerResultPO;
import com.haoxin.ai_course.modules.course.entity.VO.AcTopicAnswerResultVO;
import com.haoxin.ai_course.modules.course.service.AcStatisticsAnswerService;
import com.haoxin.ai_course.modules.course.service.AcStatisticsUserService;
import com.haoxin.ai_course.modules.course.service.AcTopicAnswerResultService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import ma.glasnost.orika.MapperFacade;

/**
 * 答题结果表
 * 
 * @author xingxiangguo
 * @email bugcn@qq.com
 * @date 2022-06-06 09:44:49
 */
@RestController
@AllArgsConstructor
@RequestMapping("/app/course/actopicanswerresult")
@Api(value = "api", tags = "app小程序-对话框题目回答结果")
@Slf4j
public class AcTopicAnswerResultController extends AbstractController {
	private final AcTopicAnswerResultService acTopicAnswerResultService;
	private final AcStatisticsAnswerService acStatisticsAnswerService;
	@Autowired
	AcStatisticsUserService acStatisticsUserService;
	MapperFacade mapperFacade;
	@Autowired
	AcTopicAnswerResultBusiness acTopicAnswerResultBusiness;
	/**
	 * 新增答题结果表
	 */
	@SysLog("新增答题结果")
	@PostMapping("/save")
	@ApiOperation("保存答题结果")
	public HttpJsonResult<AcTopicAnswerResultVO> save(@RequestBody AcTopicAnswerResultPO acTopicAnswerResultPO) {
		Long userId = getUserId();
		log.info("保存答题结果，参数：{}", JSONObject.toJSON(acTopicAnswerResultPO));
		HttpJsonResult<AcTopicAnswerResultVO> result = new HttpJsonResult<AcTopicAnswerResultVO>();
		try {
			result = acTopicAnswerResultBusiness.save(acTopicAnswerResultPO, userId);
		} catch (Exception e) {
			e.printStackTrace();
			log.error("保存答题结果失败，原因：",e.getMessage());
		}
		return result;
	}

}
